package controllers;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import render.LegajosRenderer;

@SuppressWarnings("serial")
public class ExampleList extends GenericForwardComposer {
    Listbox legajosListBox;
    
    @Override
    @SuppressWarnings("unchecked")
    public void doAfterCompose (Component comp) throws Exception {
        super.doAfterCompose(comp);
        
        legajosListBox.setModel(getLegajosModel());
        legajosListBox.setItemRenderer(new LegajosRenderer());
    }
    
    public ListModel getLegajosModel () {
        List legajos;
        
        EntityManagerFactory emf;
        emf = Persistence.createEntityManagerFactory("ConarpesaWebAppPU");
        EntityManager em = emf.createEntityManager();
        javax.persistence.Query q = em.createQuery("select c from LegLEGAJO as c");
        legajos = q.getResultList();
        return new ListModelList(legajos);
    }
}
